<template>
  <div class="app-container">
    <!-- 查询条件区域-->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-="82px">
      <!--<el-form-item label="站点名称" prop="site_name">
        <el-input
          v-model="queryParams.site_name"
          placeholder="请输入站点名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工艺体名称" prop="process_name">
        <el-input
          v-model="queryParams.process_name"
          placeholder="请输入工艺体名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--       <el-form-item label="机器人编号" prop="robot_num">-->
<!--        <el-input-->
<!--          v-model="queryParams.robot_num"-->
<!--          placeholder="请输入机器人编号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--          size="small"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="机器人名称" prop="robot_name">
        <el-input
          v-model="queryParams.robot_name"
          placeholder="请输入机器人名称"
          clearable
          @keyup.enter.native="handleQuery"
          size="small"
        />
      </el-form-item>
      <el-form-item label="更新时间">
        <el-date-picker
            v-model="queryParams.create_times"
            style="width: 215px" value-format="yyyy-MM-dd" format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
<!--      <el-form-item label="日期:" prop="scsj">-->
<!--        <div class="form_item form_content">-->
<!--           <el-date-picker v-model="queryParams.scsj" :picker-options="pickerOption" type="date" placeholder="请选择日期"></el-date-picker>-->
<!--        </div>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!--增删改查按钮区域-->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['robot:robotstate:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['robot:robotstate:export']"
        >导出</el-button>
      </el-col>
  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
<!--  数据列表区域-->
    <el-table v-loading="loading" :data="robotstateList" @selection-change="handleSelectionChange" :cell-style="{borderColor:'rgb(1 5 43)'}" :header-cell-style="{borderColor: 'rgb(1 5 43)'}" >
<!--  <el-table-column label="序号" type="index" align="center" prop="id" width="100" />-->
<!--  <el-table-column label="机器人编号" align="center" prop="robot_num" width="100" />-->
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="机器人名称" align="center" prop="robot_name" width="100" />
      <el-table-column label="轨道长度"   align="center"  prop="yxlc" :show-overflow-tooltip="true" />
      <el-table-column label="电机温度(℃)" align="center" prop="djwd" width="110" />
      <el-table-column label="电机转速(r/min)" align="center" prop="djzs" width="130" />
      <!-- <el-table-column label="电机反馈电流" align="center" prop="djfkdl" width="100" />-->
      <el-table-column label="氧气浓度(%)" align="center" prop="o2" width="110" />
      <el-table-column label="甲烷浓度(%LEL)" align="center" prop="ch4" width="130" />
      <el-table-column label="硫化氢浓度(PPM)" align="center" prop="h2s" width="130" />
      <el-table-column label="氨气浓度(PPM)" align="center" prop="nh3" width="110" />
      <el-table-column label="环境温度(℃)" align="center" prop="hjwd" width="130" />
      <el-table-column label="环境湿度(%LEL)" align="center" prop="hjsd" width="130" />
      <el-table-column label="电池1温度(℃)" align="center" prop="dc1wd" width="110" />
      <el-table-column label="电池状态" align="center" prop="dczt" width="100" />
      <el-table-column label="电池电量(%)" align="center" prop="dcdl" width="110" />
      <el-table-column label="电池电压(V)" align="center" prop="dcdy" width="110" />
      <el-table-column label="更新时间" align="center" prop="scsj" width="220px">
        <template slot-scope="scope">
          <span>{{parseTime(scope.row.scsj) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['robot:robotstate:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
<!--列表分页区域-->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList" style="background:rgb(1 5 43);"
    />
  </div>
</template>
<script>
import {delsRobotState, listRobotState} from "@/api/robot/robotstate/robotstate";
import {listSite} from "@/api/robot/site/site";
import {listProcessBody} from "@/api/robot/processbody/processbody";
import {listRobotConfig} from "@/api/robot/robotconfig/robotconfig";
import "@/assets/styles/robt-bg.css";

export default {
  data() {
    return {
      //遮罩层
      loading: true,
      //选中数组
      ids: [],
      //非单个禁用
      single: true,
      //非多个禁用
      multiple: true,
      //显示搜索条件
      showSearch: true,
      //总条数
      total: 0,
      //查询条件区域-站点下拉列表数据
      siteListselc: [],
      //机器人状态表格数据
      robotstateList:[],
      //工艺体表格数据
      processbodyListc:[],
      //工艺体--机器人表格数据
      robotstateListgyt:[],
      //弹出层标题
      title: "",
      //是否显示弹出层
      open: false,
      //查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 8,
        site_id:undefined,
        process_body_id:undefined,
        robot_config_id:undefined,
        site_name: undefined,
        process_name: undefined,
        robot_name: undefined,
        scsj:undefined,
        create_times: [],
      }
    };
  },
  created() {
    this.getList();/** 初始化机器人状态列表 */
  },
  methods: {
    /** 导出按钮操作 */
    handleExport() {
      this.download('robot/robotstate/export', {
        ...this.queryParams
      }, `monitor_${new Date().getTime()}.xlsx`)
    },
   /* scsj:null, //日期选择
    pickerOption: {
      disabledDate: time => {
        const dateVal = new Date(this.scsj).getTime();
        if (dateVal) {
          return time.getTime() > dateVal + 1;
        }
      }
    },*/
    /** 查询条件区域----查询机器人列表 */
    getOptionsgyt(id){
      this.queryParams.process_body_id=id;//设置站点id条件，查询工艺体
      this.getListgyt();
    },
    /** 查询条件区域-----查询工艺体列表 */
    getOptionszd(id){
      console.log("站点id"+id)
      this.queryParams.site_id=id;//设置站点id条件，查询工艺体
      this.getprocessbodysList();
    },
    /** 查询条件区域--查询新建查询站点列表 */
    getsiteselcList() {
      this.loading = true;
      listSite(this.queryParams).then(response => {
        this.siteListselc = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询条件区域-----查询工艺体下拉列表 */
    getprocessbodysList() {
      this.loading = true;
      listProcessBody(this.queryParams).then(response => {
        this.processbodyListc=[];
        this.processbodyListc = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询条件区域---查询机器人状态列表 */
    getListgyt() {
      this.loading = true;
      listRobotConfig(this.queryParams).then(response => {
        this.robotstateListgyt = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询机器人状态列表 */
    getList() {
      this.loading = true;
      listRobotState(this.queryParams).then(response => {
        this.robotstateList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    //表单重置
    reset() {
      this.form = {
        id: undefined,
        site_num: undefined,
        site_name: undefined,
        site_adr: undefined,
        lon: undefined,
        lat: undefined,
        creater_id:undefined,
        creater_time:undefined,
        remark: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.create_times=[];
      this.queryParams.process_body_id=null;
      this.queryParams.robot_config_id=null;
      this.queryParams.site_id=null;
      this.queryParams.site_name=null;
      this.queryParams.process_name=null;
      this.queryParams.robot_name=null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除选中的数据项？').then(function() {
        return delsRobotState(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    }
  }
};
</script>
